Expand description

A trait and implementations for unique ID generators.

This crate provides a very simple trait, Generator, that will return successive unique identifiers. Two implementations of this trait are provided which provide unique string and integer values respectively.

Example

The following shows an example of the StringGenerator implementation.

use unique_id::Generator;
use unique_id::string::StringGenerator;

let gen = StringGenerator::default();
let mut last = gen.next_id();
for _ in 1..100_000 {
    let next = gen.next_id();
    assert_ne!(last, next);
    last = next;
}

Modules

An implementation that provides random 128-bit unsigned integer values.

An implementation that provides monotonically increasing integer values.

An implementation that provides unique string values.

Traits

The primary ID generator trait, it provides for generating a new ID with next_id(). There is no implication that this returns any overall sequence of values, only that it returns a unique value for each call.

While it is required for a generator to support the Default trait, in some cases it is useful to create a new generator some some known initial value, the seed.

If the type T implements FromStr then the associated function is_valid_value determines whether the value s is valid as an ID value.

For generators that are able to reserve a unique value that is not valid as an ID.